<?php
namespace Home\Controller;
class CompanyController extends LoginController{
	function index(){
        $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
        preg_match("#http://(.*?)\.#i ",$url,$match);
        if($match[1]==www){
            $Ip = new \Org\Net\IpLocation('qqwry.dat');
            $ip = get_client_ip();
            $arr = $Ip->getlocation($ip);
            $country = $arr["country"];
            $city = iconv("GB2312","UTF-8",$country);
            $arr = explode(省,$city);
            $data=$arr["1"];
        }else{
            $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
            preg_match("#http://(.*?)\.#i ",$url,$match);
            $cityOb = M("City");
            $arr = $cityOb->where("pinyin='$match[1]'")->find();
            $data = $arr['name'];
        }
		$com = M("Gongsi");
        $num=$com->where("isshow=1 and s_city='$data'")->count();
// 		3、规定每页显示的条数
		$pageSize=8;
// 		4、实例化分页类
		$pageOb=new \Think\Page($num,$pageSize);
// 		5、获取开始位置值
		$start=$pageOb->firstRow;
// 		6、获取分页结果
		$pageStr=$pageOb->show();
		$area = $_GET["s_county"];
		if($area){
            $arr = $com->where("isshow=1 and s_county='$area'")->limit("$start,$pageSize")->order('num')->select();
            $this->assign('area',$area);
        }else{
		    $arr = $com->where("isshow=1 and s_city='$data'")->limit("$start,$pageSize")->select();
        }
		if($arr){
			$this->assign('pageStr',$pageStr);
			$this->assign('arr',$arr);
		}
        $this->getip();
        $styleOb = M("Fimg");
        $arr6 = $styleOb->select();
        $this->assign('arr6',$arr6);
     	$this->fuwuqvyu();
		$this->display();
	}
	function detail(){
		$id=$_GET["id"];
		session_start();
		$_SESSION['id']=$id;
		$ob=M("Gongsi");
		$arr = $ob->where("id=$id")->find();
		$this->assign('arr',$arr);
		$this->dongtai();
		$this->getip();
		$this->youhui();
		$this->sheji();
		$this->gongdi();
		$this->display();
	}
	function dongtai(){
	    $dongtaiOb = M("Gd_news");
        $id=$_GET['id'];
	    $arr3 = $dongtaiOb->where("pid=$id")->limit(3)->select();
	    $this->assign('arr3',$arr3);
    }
	function sheji1(){
		exit(json_encode(array('msg'=> '该方法已废弃')));
		$_POST["addtime"]=time();
		$_POST["ip"]=get_client_ip();
		$Ob=M("Liangfang");
		$re = $Ob->data($_POST)->add();
		if($re){
			echo json_encode(array('msg'=>1));
		}
	}
	function youhui(){
        $youhuiOb = M("Youhui");
        $id=$_GET['id'];
        $arr4 = $youhuiOb->where("gid=$id")->limit(2)->select();
        $this->assign('arr4',$arr4);
    }
     function layout(){
         $this->layout();
     }
     function sheji(){
        $shejiOb = M("Shejishi");
         $id=$_GET['id'];
        $arr2 = $shejiOb->where("sid=$id")->limit(5)->select();
        $this->assign('arr2',$arr2);
     }
     function design(){
         $inOb = M("Gongsi");
         $id=$_GET['id'];
         $arr = $inOb->where("id=$id")->find();
         $this->assign('arr',$arr);
	    $shejiOb = M("Shejishi");
	    $arr1 = $shejiOb->where("sid=$id")->limit(14)->select();
	    $this->assign(arr1,$arr1);
         $this->getip();
	    $this->display();
     }
//    function add(){
//        $bjadd = M("Baojia");
//        $addtime=time();
//        $ip = get_client_ip();
//        $re = $bjadd->data($_POST)->add();
//        if($re){
//            echo json_encode(array('msg'=>1));
//        }else{
//
//        }
//    }
    function gongdi(){
	    $gongdiOb = M("Gongdi");
        $id=$_GET['id'];
	    $arr1 = $gongdiOb->where("gid=$id")->limit(3)->select();
	    $this->assign('arr1',$arr1);

    }

	function fuwuqvyu(){
		$fuwuOb = M("City");
        $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
        preg_match("#http://(.*?)\.#i ",$url,$match);
        if($match[1]==www){
        $Ip = new \Org\Net\IpLocation('qqwry.dat');
        $ip = get_client_ip();
        $arr = $Ip->getlocation($ip);
        $country = $arr["country"];
        $city = iconv("GB2312","UTF-8",$country);
        $arr = explode(省,$city);
        $data=$arr["1"];
        $arr6 = $fuwuOb->where("name='$data'")->find();
        }else{
            $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
            preg_match("#http://(.*?)\.#i ",$url,$match);
            $data = $match[1];
            $arr6 = $fuwuOb->where("pinyin='$data'")->find();
        }
		$areaOb = M("Area");
		$code = $arr6["code"];
		$arr7 = $areaOb->where("citycode=$code")->select();
		$this->assign('arr7',$arr7);
	}
	function koubei(){
	    $haoping = rand(1000,10000);
	    $this->assign('haoping',$haoping);
    }
    function introduction(){
	    $inOb = M("Gongsi");
        $id=$_GET['id'];
	    $arr = $inOb->where("id=$id")->find();
	    $this->assign('arr',$arr);
        $zizhiOb = M("Comzizhi");
        $arr8 = $zizhiOb->where("lei=$id")->select();
        $this->assign('arr8',$arr8);
        $this->getip();
        $this->display();
    }
    function zizhi(){
        $inOb = M("Gongsi");
        $id=$_GET['id'];
        $arr1 = $inOb->where("id=$id")->find();
        $this->assign('arr1',$arr1);
	    $zizhiOb = M("Comzizhi");
	    $arr = $zizhiOb->where("lei=$id")->select();
	    $this->assign('arr',$arr);
        $this->getip();
	    $this->display();
    }
    function zixun(){
        $ob = M('Gongsi');
        $id=$_GET['id'];
        $arr = $ob->where("id=$id")->find();
        $this->assign('arr',$arr);
        $dongtaiOb = M("Gd_news");
        $id=$_GET['id'];

            $num=$dongtaiOb->count();
// 		3、规定每页显示的条数
            $pageSize=12;
// 		4、实例化分页类
            $pageOb=new \Think\Page($num,$pageSize);
// 		5、获取开始位置值
            $start=$pageOb->firstRow;
// 		6、获取分页结果
            $pageStr=$pageOb->show();
            $arr1 = $dongtaiOb->where("pid=$id")->limit("$start,$pageSize")->order('id desc')->select();
            $this->assign('pageStr',$pageStr);
        if($arr1){
            $this->assign('arr1',$arr1);
        }
        $this->getip();
        $this->display();
    }
    function zixun_about(){
        $ob = M('Gongsi');
        $pid=$_GET['pid'];
        $arr = $ob->where("id=$pid")->find();
        $this->assign('arr',$arr);
	    $zixunOb = M("Gd_news");
        $id=$_GET['id'];
	    $arr1 = $zixunOb->where("id=$id")->find();
        $this->assign('arr1',$arr1);
        $this->getip();
        $this->display();
    }
    function visit(){
	    $ob = M('Gongsi');
        $id=$_GET['id'];
	    $arr = $ob->where("id=$id")->find();
	    $this->assign('arr',$arr);
	    $gongdiOb = M("Gongdi");
        $num=$gongdiOb->where("gid=$id")->count();
// 		3、规定每页显示的条数
        $pageSize=5;
// 		4、实例化分页类
        $pageOb=new \Think\Page($num,$pageSize);
// 		5、获取开始位置值
        $start=$pageOb->firstRow;
// 		6、获取分页结果
        $pageStr=$pageOb->show();
        $arr1 = $gongdiOb->where("gid=$id")->limit("$start,$pageSize")->order('id desc')->select();
        $this->assign('pageStr',$pageStr);
        if($arr1){
            $this->assign('arr1',$arr1);
        }
        $this->getip();
	    $this->display();
    }
    function getImg($a,$b,$c){
        $gondi1Ob = M("Gongdi2");
        $condition['pid'] = $a;
        $condition['overstatus'] = $b;
        $arr = $gondi1Ob->where($condition)->select();
        $this->assign($c,$arr);
    }
    function visit_about(){
        $ob = M('Gongsi');
        $gid=$_GET['gid'];
        $arr = $ob->where("id=$gid")->find();
        $this->assign('arr',$arr);
        $id=$_GET['id'];
        $gongdiOb = M("Gongdi");
        $arr1 = $gongdiOb->where("id=$id")->find();
        $this->assign('arr1',$arr1);
        $this->getImg($id,1,arr2);
        $this->getImg($id,2,arr3);
        $this->getImg($id,3,arr4);
        $this->getImg($id,4,arr5);
        $this->getImg($id,5,arr6);
        $this->getip();
        $this->display();
    }
    function visited(){
        $ob = M('Gongsi');
        $id=$_GET["id"];
        $gid=$_GET['id'];
        $arr1 = $ob->where("id=$id")->find();
        $this->assign('arr1',$arr1);
        $gongdiOb = M("Gongdi");
        $num=$gongdiOb->where("gid=$id")->count();
// 		3、规定每页显示的条数
        $pageSize=5;
// 		4、实例化分页类
        $pageOb=new \Think\Page($num,$pageSize);
// 		5、获取开始位置值
        $start=$pageOb->firstRow;
// 		6、获取分页结果
        $pageStr=$pageOb->show();
        $arr = $gongdiOb->where("gid=$id AND overstatus=5")->limit("$start,$pageSize")->order('id desc')->select();
        $this->assign('pageStr',$pageStr);
        if($arr){
            $this->assign('arr',$arr);
        }
        $this->getip();
        $this->display();
    }
    function viting(){
        $ob = M('Gongsi');
        $id=$_GET['id'];
        $arr1 = $ob->where("id=$id")->find();
        $this->assign('arr1',$arr1);
        $gongdiOb = M("Gongdi");
        $num=$gongdiOb->where("gid=$id")->count();
// 		3、规定每页显示的条数
        $pageSize=5;
// 		4、实例化分页类
        $pageOb=new \Think\Page($num,$pageSize);
// 		5、获取开始位置值
        $start=$pageOb->firstRow;
// 		6、获取分页结果
        $pageStr=$pageOb->show();
        $arr = $gongdiOb->where("gid=$id AND overstatus<5")->limit("$start,$pageSize")->order('id desc')->select();
        $this->assign('pageStr',$pageStr);
        if($arr){
            $this->assign('arr',$arr);
        }
        $this->getip();
        $this->display();
	}

}
